package Lee_code;

/**
 * @author blh
 * @date 2024年08月05日 19:08
 */
public class Lee_86_85 {
    public ListNode partition(ListNode head, int x) {
        if (head == null) {
            return null;
        }
        ListNode smallDummy = new ListNode(-1);
        ListNode tempSmall = smallDummy;
        ListNode largeDummy = new ListNode(-1);
        ListNode tempLarge = largeDummy;

        while (head != null) {
            if (head.val >= x) {
                tempLarge.next = head;
                tempLarge = tempLarge.next;
            } else {
                tempSmall.next = head;
                tempSmall = tempSmall.next;
            }
            ListNode temp = head;
            head = head.next;
            temp.next = null;

        }
        tempSmall.next = largeDummy.next;
        largeDummy.next = null;
        return smallDummy.next;
    }
}
